package com.iflysse.services.impl;

import com.iflysse.dao.ClassDao;
import com.iflysse.pojo.bo.resp.ClassBoResp;
import com.iflysse.pojo.bo.resp.ClassListBoResp;
import com.iflysse.pojo.po.resp.ClassPoResp;
import com.iflysse.services.ClassService;
import com.iflysse.util.CommonUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    public static final Logger log = Logger.getLogger(ActivityServiceImpl.class);

    @Autowired
    ClassDao classDao;
    /**
     * 获取所有行政班级
     *
     * @return
     */
    @Override
    public ClassListBoResp loadAllClasses() throws SQLException {
        //获取所有行政班级
        List<ClassPoResp> allClass = classDao.getAllClass();
        ClassListBoResp classListBoResp = new ClassListBoResp();
        classListBoResp.setClassBoRespList(new ArrayList<>());
        //类型转换
        allClass.forEach(classPoResp -> {
            ClassBoResp classBoResp = CommonUtil.objToObj(classPoResp, ClassBoResp.class);
            classListBoResp.getClassBoRespList().add(classBoResp);
        });
        return classListBoResp;
    }
}
